package com.yonyou.pmclouds.problemlog.process;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import com.yonyou.pmclouds.basecom.bp.processor.MultiProcessor;
import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.problemlog.entity.ProblemLogBillStatus;
import com.yonyou.pmclouds.problemlog.entity.ProblemLogVO;
/**
 * 批量新增前规则
 * @author fangpengc
 *
 */
public class ProblemLogBeforeMultiAddProcess implements MultiProcessor<ProblemLogVO>{

    @Override
    public void process(ProblemLogVO[] vos, ProblemLogVO[] origs) throws BusinessException {
        if(ArrayUtils.isEmpty(vos)) {
            return ;
        }
        for (ProblemLogVO problemLogVO : vos) {
            dealItems(problemLogVO);
        }
        
    }

    private void dealItems(ProblemLogVO vo) throws BusinessException {
        if(vo == null) {
            throw new BusinessException("新增问题记录单为空,请检查!");
        } else if(StringUtils.isEmpty(vo.getPk_rectificationer())) {
            throw new BusinessException("整改人为空");
        } else if(StringUtils.isEmpty(vo.getPk_problemreason())) {
            throw new BusinessException("问题原因为空");
        }
        // 设置单据类型
        vo.setBill_type(BillTypeConst.PROBLEMLOG_BILLTYPE);
        vo.setBillstatus(ProblemLogBillStatus.STATUS_REPAIRING);
    }
}
